package com.edooteach.tencent.web.controller.auth.weapp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.demo2do.core.entity.exception.BusinessException;
import com.demo2do.core.entity.result.HttpResult;
import com.demo2do.core.utils.JsonUtils;
import com.edooteach.tencent.entity.weappnotice.WeappNoticeSender;
import com.edooteach.tencent.handle.WeappNoticeHandler;

/**
 * 
 * @author mohanlan
 *
 */
@RestController
@RequestMapping("/weapp/notice")
public class WeappNoticeSenderController {
	
	private static final Logger logger = LoggerFactory.getLogger(WeappNoticeSenderController.class);
	
	@Autowired
	private WeappNoticeHandler weappNoticeHandler;
	
	/**
	 * 
	 * @param weappNoticeSender
	 * @return
	 */
	@RequestMapping(value = "/send", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public HttpResult send(@RequestBody WeappNoticeSender weappNoticeSender) {
		
		logger.info("call weapp notice send with params [{}]", JsonUtils.toJson(weappNoticeSender));
		
		if(weappNoticeSender != null && weappNoticeSender.isVaild()) {
			return weappNoticeHandler.send(weappNoticeSender);
		}
		
		throw BusinessException.newInstance("400", "参数异常");
	}
}
